//
//  FileCell.swift
//  CreateMyCode
//
//  Created by zhibao on 2024/2/27.
//

import UIKit
class FileCell: UITableViewCell {
    fileprivate var qrImgView = UIImageView()
    fileprivate var nameLabel = UILabel()
    fileprivate var detailLabel = UILabel()
    fileprivate var timeLabel = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.clear
        let bgView = UIView()
        bgView.backgroundColor = MYColor.color(withHexString: "ffffff", alpha: 0.4)
        bgView.layer.cornerRadius = 5
        bgView.layer.borderColor = MYColor.color(withHexString: "999999").cgColor
        self.contentView.addSubview(bgView)
        bgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:10))
            make.top.equalTo(pixw(p:5))
            make.right.equalTo(pixw(p:-10))
            make.bottom.equalTo(pixw(p:-5))
            make.height.equalTo(pixw(p:75))
        }
        bgView.layer.shadowColor = UIColor.gray.cgColor // 阴影的颜色
        bgView.layer.shadowOpacity = 0.2 //阴影的不透明度，取值范围是0.0（完全透明）到1.0（完全不透明）
        bgView.layer.shadowOffset = CGSize(width: 2, height: 2) // 阴影的偏移量，这里向右下偏移(5, 5)
        bgView.layer.shadowRadius = 5 // 阴影的模糊半径
        
        qrImgView.backgroundColor = MYColor.color(withHexString: "f2f2f2")
        qrImgView.contentMode = .scaleAspectFit
        bgView.addSubview(qrImgView)
        qrImgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:10))
            make.top.equalTo(pixw(p:10))
            make.bottom.equalTo(pixw(p:-10))
            make.width.height.equalTo(pixw(p:55))
        }
        
        nameLabel.font = MY_SCALE_SemiboldFONT(13)
        nameLabel.text = "--"
        nameLabel.textColor = MYBlock
        bgView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(qrImgView.snp.right).offset(pixw(p:15))
            make.top.equalTo(pixw(p:12))
        }
        
        detailLabel.font = MY_SCALE_RegularFONT(12)
        detailLabel.text = "2022-04-13 14:02:34"
        detailLabel.textColor = MYColor.color(withHexString: "666666")
        bgView.addSubview(detailLabel)
        detailLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel)
            make.right.equalTo(pixw(p:-35))
            make.top.equalTo(nameLabel.snp.bottom).offset(pixw(p:2))
        }
        
        timeLabel.font = MY_SCALE_RegularFONT(10)
        timeLabel.text = "2022-04-13 14:02:34"
        timeLabel.textColor = MYColor.color(withHexString: "888888")
        bgView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel)
            make.right.equalTo(pixw(p:-15))
            make.top.equalTo(detailLabel.snp.bottom).offset(pixw(p:2))
        }
        
        let rightImgView = UIImageView(image: UIImage(named: "comm_right"))
        bgView.addSubview(rightImgView)
        rightImgView.snp.makeConstraints { make in
            make.right.equalTo(bgView).offset(pixw(p:-10))
            make.centerY.equalTo(self)
        }
    }
    
    func update(dic:[String:Any]){
        let custom_parametersDic = Helper.dictionary(withJsonString: dic["custom_parameters_str"] as! String) as! [String:Any]
        nameLabel.text = custom_parametersDic["nav"] as? String ?? ""
        detailLabel.text = dic["content"] as? String ?? ""
        timeLabel.text = dic["create_date"] as? String ?? ""
        qrImgView.yy_setImage(with: URL(string: dic["url"] as! String), options: .showNetworkActivity)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
